﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyWrite.API.Appicant.Command;
using B.S.DataBase.MyWrite.API.Appicant.Command.Approval;
using B.S.DataBase.MyWrite.API.Appicant.Command.Roles;
using B.S.DataBase.MyWrite.API.Appicant.Command.Users;

using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyProject.API.Controllers
{
    /// <summary>
    /// 用户管理--写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<User>> AddUser(AddUserCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> DelUser(DelUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> UpdateUser(UpdateUserCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 角色添加命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<APIResult<Role>> AddRole(AddRoleCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 角色删除
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public async Task<APIResult<object>> DelRole(DelRoleCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 角色更新
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public Task<APIResult<object>> UpDateRole(UpdateRoleCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 删除角色用户关联
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public Task<APIResult<object>> DelUR(DelURCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public async Task<APIResult<object>> PLAdd(UserRoleCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 依据角色删除选择的用户
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPut]
        public Task<APIResult<RoleUser>> RemoveRole(RemoveRoleCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        #region 菜单

        /// <summary>
        /// 添加菜单数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]
        public  async Task<APIResult<Menu>> CreateMenu(CreateMenuCommends request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 修改菜单数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPut]
        public async Task<APIResult<Menu>> UpDataMenu(UpDataMenuCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPut("DelMenu")]
        public Task<APIResult<Menu>> DelMenu(DelMenuCommends request, CancellationToken cancellationToken)
        {
            return  mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 创建角色菜单数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]

        public async Task<APIResult<object>> CreateRoleMenu(CreateRoleMenuCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }
        #endregion


        #region  审批


        /// <summary>
        /// 添加申请表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]
        public async Task<APIResult<LeaveApplications>> CreateLeaveApplication(CreateLeaveApplicationCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }


        /// <summary>
        /// 删除请假申请(逻辑删除)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPut]
        public async Task<APIResult<LeaveApplications>> DelLeaveApplication(DelLeaveApplicationCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 修改申请表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPut]
        public async Task<APIResult<LeaveApplications>> UpLeaveApplication(UpLeaveApplicationCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }



        /// <summary>
        /// 更新状态以及添加审批记录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpPost]
        public async Task<APIResult<LeaveApplications>> AppUpdata(AppUpdataCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }
        #endregion

    }
}
